<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script src="./vue.js"></script>
    <div id="app">
      <div>{{time}}</div>
      <button @click="click">{{status}}</button>
    </div>
    <script>
      var app = new Vue({
        el: "#app",
        data: {
          time: 30,
          status: "开始",
        },
        methods: {
          computedtime(status) {
            // let now = new Date();
            // let deadline = new Date("2022-04-12");
            // let countdown = deadline - now;
            // this.time = Math.floor(countdown / 1000);
            // console.log(11);
            if (status == 0) {
              this.time--;
              console.log(11);
              console.log(this.time);
            } else {
              this.time = this.time;
            }
            setTimeout(this.computedtime(status), 1000);
          },
          click() {
            // console.log(1111);
            if (this.status == "开始") {
              this.status = "暂停";
              this.computedtime(0);
            } else {
              this.status = "开始";
              this.computedtime(1);
            }
          },
        },
      });
    </script>
  </body>
</html>
